<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
    export default {
        mixins: [Vue.prototype.$vFN.Mixins.Base],
        data() {
            return {
                load:false,
                imgSuffixValue: '',
                videoSuffixValue: '',
                voiceSuffixValue: '',
                form: {
                    // 支持图片后缀     
                    imgSuffixLst: [],
                    // 支持图片大小  kb
                    imgSize: null,

                    // 支持视频后缀 
                    videoSuffixLst: [],
                    // 支持视频大小 kb
                    videoSize: null,

                    // 支持音频后缀 
                    voiceSuffixLst: [],
                    // 支持音频大小 kb
                    voiceSize: null,
                },
            };
        },
        methods: {

            // 初始化
            init() {
                this.getData();
            },
            addImg() {
                if (this.imgSuffixValue == "") {
                    this.$vFN.Tools.messageError("添加图片扩展后缀不能为空");
                    return
                }
                let _is = this.form.imgSuffixLst.some(item => {
                    return (item == this.imgSuffixValue)
                })
                if(_is){
                    this.$vFN.Tools.messageError("添加图片扩展后缀已存在");
                    return
                }
                this.form.imgSuffixLst.push(this.imgSuffixValue)
                this.imgSuffixValue = "";
            },
            delImg(_index) {
                this.form.imgSuffixLst.splice(_index, 1);
            },
            addVideo() {
                if (this.videoSuffixValue == "") {
                    this.$vFN.Tools.messageError("添加视频扩展后缀不能为空");
                    return
                }
                let _is = this.form.videoSuffixLst.some(item => {
                    return (item == this.videoSuffixValue)
                })
                if(_is){
                    this.$vFN.Tools.messageError("添加视频扩展后缀已存在");
                    return
                }
                this.form.videoSuffixLst.push(this.videoSuffixValue)
                this.videoSuffixValue = "";
            },
            delVideo(_index) {
                this.form.videoSuffixLst.splice(_index, 1);
            },
            addVoice() {
                if (this.voiceSuffixValue == "") {
                    this.$vFN.Tools.messageError("添加音频扩展后缀不能为空");
                    return
                }
                let _is = this.form.voiceSuffixLst.some(item => {
                    return (item == this.voiceSuffixValue)
                })
                if(_is){
                    this.$vFN.Tools.messageError("添加音频扩展后缀已存在");
                    return
                }
                this.form.voiceSuffixLst.push(this.voiceSuffixValue)
                this.voiceSuffixValue = "";
            },
            delVoice(_index) {
                this.form.voiceSuffixLst.splice(_index, 1);
            },

            // 获取内容信息
            async getData() {
                let _data = await this.$vFN.Http.post({
                    url: "mall-admin/file-config/getItem",
                },window);
                if (_data._ok) {
                    for (let i in this.form) {
                        this.form[i] = _data.data[i]
                    }
                    this.load = true;
                }
            },
            
            // 验证 
            validate() {
                return new Promise((resolve, reject) => {
                    this.$refs["editForm"].validate((valid) => {
                        valid ? resolve(true) : resolve(false)
                    });
                });
            },
            // 提交
            async submit() {
                if (!await this.validate()) {
                    return
                }
                // console.error(this.imgSuffixLst.split("\n"))
                let _data = await this.$vFN.Http.post({
                    url: "mall-admin/file-config/saveOrUpdate",
                    data: {
                        // 支持图片后缀     
                        imgSuffixLst: this.form.imgSuffixLst,
                        // 支持图片大小  kb
                        imgSize: this.form.imgSize,

                        // 支持视频后缀 
                        videoSuffixLst: this.form.videoSuffixLst,
                        // 支持视频大小 kb
                        videoSize: this.form.videoSize,

                        // 支持音频后缀 
                        voiceSuffixLst: this.form.voiceSuffixLst,
                        // 支持音频大小 kb
                        voiceSize: this.form.voiceSize,
                    },
                },window);
                if (_data._ok) {
                    this.$vFN.Tools.messageSuccess("保存成功");
                    this.init();
                }
            },
        },
        mounted() {
            this.init();

        },
        activated() {},
    };
</script>